"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

class FingerValidationEntry():
    """Class for incorrect fingertable entries.
    
    Consists of the index of the incorrect finger, the nameBundle the finger is currently set to, the calculated
    string-value for that finger and the nameBundle the finger should point to.
    
    Attributes:
        __i: the i-th finger
        __currentFingerNameBundle: the name bundle of the current finger (string)
        __calculatedFingerString: the calculated finger (string)
        __shouldBeFingerNameBundle: the name bundle of the should be finger (string)
    """
    
    def __init__(self, i, currentFingerNameBundle, calculatedFingerString, shouldBeFingerNameBundle):
        self.__i = i
        self.__currentFingerNameBundle = currentFingerNameBundle
        self.__calculatedFingerString = calculatedFingerString
        self.__shouldBeFingerNameBundle = shouldBeFingerNameBundle
    
    def getIndex(self):
        return self.__i
    
    def getCurrentFingerNameBundle(self):
        return self.__currentFingerNameBundle
    
    def getCalculatedFingerString(self):
        return self.__calculatedFingerString
    
    def getShouldBeFingerNameBundle(self):
        return self.__shouldBeFingerNameBundle
    
    
class BackupValidationEntry():
    """Class for incorrect backups.
    
    Attributes:
        __backupFromName: the name of the backup source (string)
        __errorString: the string representation of the failure
    """
    
    def __init__(self, backupFromName, errorString):
        if backupFromName != None:
            backupFromName = unicode(backupFromName)
        if errorString != None:
            errorString = unicode(errorString)
        self.__backupFromName = backupFromName
        self.__errorString = errorString
        
    def getBackupFromName(self):
        return self.__backupFromName
    
    def getErrorString(self):
        return self.__errorString


class RingReportEntry():
    """Used during the validation of the ring.
    
    Attributes:
        __identity: the current identity (PeerInfo instance)
        __lowLevelPeers: the list of online low level peers
        __backupContent: the list of the current stored backups
        __connectedIdentities: the list of all current connected identities
    """
    
    def __init__(self, identity, backupContent, connectedIdentities):
        self.__identity = identity
        self.__lowLevelPeers = []
        self.__backupContent = backupContent
        self.__connectedIdentities = connectedIdentities
    
    def getIdentity(self):
        return self.__identity
    
    def getBackupContent(self):
        return self.__backupContent
    
    def getConnectedIdentities(self):
        return self.__connectedIdentities
    
    def getLowLevelPeers(self):
        return self.__lowLevelPeers
    
    def addLowLevelPeer(self, peer):
        self.__lowLevelPeers.append(peer)
        
    def contains(self, username):
        if self.__connectedIdentities != None:
            for identity in self.__connectedIdentities:
                if identity.getName() == username:
                    return True
        return False
    
    
###########
## TYPES ##
###########


class ConnectionType:
    """The eight different types of remote connections."""
    
    MESSAGE_EXCHANGE = 'message_exchange'
    AUTHENTICATION = 'auth'
    RESPONSIBILITY_SEARCH = 'resp_search'
    FINGERTABLE = 'fingertable'
    PEERUPDATE = 'networkupdate'
    BACKUP = 'backup'
    CRASH = 'crash'
    GROUP_MANAGEMENT = 'group_management'
        
        
class RingReportType:
    """The three types of ring reports."""
    
    PRINT_RING = 'print'
    VALIDATE_RING = 'validate'
    VALIDATE_FINGERS_AND_BACKUP = "validateFingersAndBackup"
    
    
class FingertableCalculationType:
    """The two types for finger table calculations."""
    
    LEAVE = 'leave'
    JOIN = 'join'


class CallbackReactType:
    """The four types of callbacks."""
    
    DISPLAYGROUP = 'display_group' #display group in list
    DISPLAYGROUPDETAILS = 'display_group_details' #display details in groupdetailswidget
    SEARCHMEMBER_INITSYNCH = 'search_member_init_synch' #poll media content from callbacked members
    SEARCHMEMBER_SENDMEDIA = 'search_member_send_media' #send media-content to callbacked user
    
